package com.rz.paas.test.inChannel

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.viewModels
import androidx.lifecycle.Observer
import androidx.navigation.Navigation
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.NavigationUI
import com.rz.paas.test.LoginActivity
import com.rz.paas.test.R
import com.rz.paas.test.base.MiddleActivity
import com.rz.paas.test.constant.AppConstant
import com.rz.paas.test.inChannel.viewModel.CommunicationViewModel
import kotlinx.android.synthetic.main.activity_in_channel.*
import kotlinx.android.synthetic.main.fragment_channel_setting.*

class InChannelActivity : MiddleActivity() {

    val communicationViewModel by viewModels<CommunicationViewModel>()

    companion object {

        fun open(context: Context, mode: Int) {
            val intent = Intent(context, InChannelActivity::class.java)
            intent.putExtra(AppConstant.COMMUNICATION_MODE, mode)
            context.startActivity(intent)
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_in_channel)

        setSupportActionBar(toolbar)
        val appBarConfiguration = AppBarConfiguration.Builder().setFallbackOnNavigateUpListener {
            finish()
            true
        }.build()

        val navController = Navigation.findNavController(this, R.id.nav_host_fragment)
        NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration)

        supportActionBar?.hide()


        communicationViewModel.finishActivity.observe(this, Observer {
            if (it)
                finish()
        })

        communicationViewModel.setCommunicationMode(intent.getIntExtra(AppConstant.COMMUNICATION_MODE,0))
    }


}